package vip.xiaomoli.courier.component.timewheel;

import vip.xiaomoli.courier.component.CourierExecutor;
import vip.xiaomoli.courier.dao.CourierDao;
import vip.xiaomoli.courier.model.TaskInfo;

public class CourierTask implements Runnable {

	/** 位于时间轮上的第几圈 */
	private Integer cycleNum;

	private TaskInfo ti;

	private CourierDao dao;

	public CourierTask(TaskInfo ti, CourierDao dao) {
		super();
		this.ti = ti;
		this.dao = dao;
	}

	@Override
	public void run() {
		CourierExecutor.execute(ti, dao);
	}

	/**
	 * 	倒计数，为0时即可执行此任务
	 */
	void countDown() {
        this.cycleNum--;
    }

	Integer getCycleNum() {
		return cycleNum;
	}

	void setCycleNum(Integer cycleNum) {
		this.cycleNum = cycleNum;
	}

	@Override
	public String toString() {
		return "Task[cycleNum=" + cycleNum + "], " + ti.getCourierName() + ", " + ti.getParam();
	}

}